<!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1"><meta name="format-detection" content="telephone=no"><meta name="apple-mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-status-bar-style" content="black"><link rel="icon" href="/images/icons/favicon-16x16.png?v=2.8.0" type="image/png" sizes="16x16"><link rel="icon" href="/images/icons/favicon-32x32.png?v=2.8.0" type="image/png" sizes="32x32"><meta name="description" content="Using a URDF in Gazebo 在Gazebo中使用URDF         原文链接: https:&#x2F;&#x2F;wiki.ros.org&#x2F;urdf&#x2F;Tutorials&#x2F;Using a URDF in Gazebo  Description: Preliminary tutorial on how to spawn and control your robot in">
<meta property="og:type" content="article">
<meta property="og:title" content="【urdf_tutorials】Using a URDF in Gazebo 在Gazebo中使用URDF">
<meta property="og:url" content="http://hipposox.github.io/2023/01/10/urdf-tutorials-04/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="Using a URDF in Gazebo 在Gazebo中使用URDF         原文链接: https:&#x2F;&#x2F;wiki.ros.org&#x2F;urdf&#x2F;Tutorials&#x2F;Using a URDF in Gazebo  Description: Preliminary tutorial on how to spawn and control your robot in">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://www.helloimg.com/images/2023/01/12/oGcCSE.png">
<meta property="og:image" content="https://www.helloimg.com/images/2023/01/12/oGcRy9.png">
<meta property="article:published_time" content="2023-01-10T09:03:01.000Z">
<meta property="article:modified_time" content="2023-01-12T15:29:34.965Z">
<meta property="article:author" content="HippoSoX">
<meta property="article:tag" content="ros">
<meta property="article:tag" content="URDF">
<meta property="article:tag" content="Gazebo">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://www.helloimg.com/images/2023/01/12/oGcCSE.png"><title>【urdf_tutorials】Using a URDF in Gazebo 在Gazebo中使用URDF | Hexo</title><link ref="canonical" href="http://hipposox.github.io/2023/01/10/urdf-tutorials-04/"><link rel="dns-prefetch" href="https://cdn.jsdelivr.net"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.12.1/css/all.min.css" type="text/css"><link rel="stylesheet" href="/css/index.css?v=2.8.0"><link rel="stylesheet" href="css/custom.css"><script>var Stun = window.Stun || {};
var CONFIG = {
  root: '/',
  algolia: undefined,
  assistSearch: undefined,
  fontIcon: {"prompt":{"success":"fas fa-check-circle","info":"fas fa-arrow-circle-right","warning":"fas fa-exclamation-circle","error":"fas fa-times-circle"},"copyBtn":"fas fa-copy"},
  sidebar: {"offsetTop":"20px","tocMaxDepth":6},
  header: {"enable":true,"showOnPost":true,"scrollDownIcon":false},
  postWidget: {"endText":true},
  nightMode: {"enable":true},
  back2top: {"enable":true},
  codeblock: {"style":"default","highlight":"dark","wordWrap":false},
  reward: false,
  fancybox: false,
  zoomImage: {"gapAside":"20px"},
  galleryWaterfall: undefined,
  lazyload: true,
  pjax: undefined,
  externalLink: {"icon":{"enable":true,"name":"fas fa-external-link-alt"}},
  shortcuts: undefined,
  prompt: {"copyButton":"复制","copySuccess":"复制成功","copyError":"复制失败"},
  sourcePath: {"js":"js","css":"css","images":"images"},
};

window.CONFIG = CONFIG;</script><meta name="generator" content="Hexo 5.4.2"></head><body><div class="container" id="container"><header class="header" id="header"><div class="header-inner"><nav class="header-nav header-nav--fixed"><div class="header-nav-inner"><div class="header-nav-menubtn"><i class="fas fa-bars"></i></div><div class="header-nav-menu"><div class="header-nav-menu-item"><a class="header-nav-menu-item__link" href="/"><span class="header-nav-menu-item__icon"><i class="fas fa-home"></i></span><span class="header-nav-menu-item__text">首页</span></a></div><div class="header-nav-menu-item"><a class="header-nav-menu-item__link" href="/archives/"><span class="header-nav-menu-item__icon"><i class="fas fa-folder-open"></i></span><span class="header-nav-menu-item__text">归档</span></a></div><div class="header-nav-menu-item"><a class="header-nav-menu-item__link" href="/categories/"><span class="header-nav-menu-item__icon"><i class="fas fa-layer-group"></i></span><span class="header-nav-menu-item__text">分类</span></a></div><div class="header-nav-menu-item"><a class="header-nav-menu-item__link" href="/tags/"><span class="header-nav-menu-item__icon"><i class="fas fa-tags"></i></span><span class="header-nav-menu-item__text">标签</span></a></div></div><div class="header-nav-mode"><div class="mode"><div class="mode-track"><span class="mode-track-moon"></span><span class="mode-track-sun"></span></div><div class="mode-thumb"></div></div></div></div></nav><div class="header-banner"><div class="header-banner-info"><div class="header-banner-info__title">erocool</div><div class="header-banner-info__subtitle">You know what</div></div></div></div></header><main class="main" id="main"><div class="main-inner"><div class="content-wrap" id="content-wrap"><div class="content" id="content"><!-- Just used to judge whether it is an article page--><div id="is-post"></div><div class="post"><header class="post-header"><h1 class="post-title">【urdf_tutorials】Using a URDF in Gazebo 在Gazebo中使用URDF</h1><div class="post-meta"><span class="post-meta-item post-meta-item--createtime"><span class="post-meta-item__icon"><i class="far fa-calendar-plus"></i></span><span class="post-meta-item__info">发表于</span><span class="post-meta-item__value">2023-01-10</span></span><span class="post-meta-item post-meta-item--updatetime"><span class="post-meta-item__icon"><i class="far fa-calendar-check"></i></span><span class="post-meta-item__info">更新于</span><span class="post-meta-item__value">2023-01-12</span></span></div></header><div class="post-body">
        <h1 id="using-a-urdf-in-gazebo-在gazebo中使用urdf"   >
          <a href="#using-a-urdf-in-gazebo-在gazebo中使用urdf" class="heading-link"><i class="fas fa-link"></i></a><a class="markdownIt-Anchor" href="#using-a-urdf-in-gazebo-在gazebo中使用urdf"></a> Using a URDF in Gazebo 在Gazebo中使用URDF</h1>
      
<blockquote>
<p>原文链接: <span class="exturl"><a class="exturl__link"   target="_blank" rel="noopener" href="https://wiki.ros.org/urdf/Tutorials/Using%20a%20URDF%20in%20Gazebo" >https://wiki.ros.org/urdf/Tutorials/Using a URDF in Gazebo</a><span class="exturl__icon"><i class="fas fa-external-link-alt"></i></span></span></p>
</blockquote>
<p>Description: Preliminary tutorial on how to spawn and control your robot in Gazebo.</p>
<p>描述：关于如何在Gazebo中繁殖和控制机器人的初步教程。</p>
<p>Keywords: URDF, Gazebo</p>
<p>关键词：URDF、Gazebo</p>
<p>Tutorial Level: INTERMEDIATE</p>
<p>教程级别：中级</p>
<p>Please download the URDF simulation tutorial from github or using aptitude, i.e. for ROS melodic:</p>
<p>请从github下载URDF模拟教程或使用apt，以ROS melodic为例：</p>
<figure class="highlight sh"><div class="table-container"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo apt-get install ros-melodic-urdf-sim-tutorial </span><br></pre></td></tr></table></div></figure>
<span id="more"></span>

        <h2 id="1-nonfunctional-gazebo-interface"   >
          <a href="#1-nonfunctional-gazebo-interface" class="heading-link"><i class="fas fa-link"></i></a><a class="markdownIt-Anchor" href="#1-nonfunctional-gazebo-interface"></a> 1 Nonfunctional Gazebo Interface</h2>
      
<p>We can spawn the model we already created into Gazebo using gazebo.launch</p>
<p>我们可以使用Gazebo.launch将我们已经创建的模型派生到Gazebo中</p>
<figure class="highlight sh"><div class="table-container"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">roslaunch urdf_sim_tutorial gazebo.launch </span><br></pre></td></tr></table></div></figure>
<p>This launch file</p>
<p>此启动文件</p>
<ul>
<li>
<p>Loads the urdf from the macro tutorial into the parameter description (as before)</p>
</li>
<li>
<p>Launches an empty gazebo world</p>
</li>
<li>
<p>Runs the script to read the urdf from the parameter and spawn it in gazebo.</p>
</li>
<li>
<p>By default, the gazebo gui will also be displayed, and look like this:</p>
</li>
<li>
<p>将urdf从宏教程加载到参数描述中（如前所述）</p>
</li>
<li>
<p>启动一个空的露台世界</p>
</li>
<li>
<p>运行脚本从参数中读取urdf并在gazebo中生成它。</p>
</li>
<li>
<p>默认情况下，还将显示gazebo gui，如下所示：</p>
</li>
</ul>
<p>Note: If you download the package directly from git, then please create a workspace and put the two folders under  $yourworkspacefolder/src  and compile with command  catkin_make.</p>
<p>注意：如果您直接从git下载包，请创建一个工作区，并将这两个文件夹放在$yourworkspacefolder/src下，然后使用命令catkin_make进行编译。</p>
<p><a target="_blank" rel="noopener" href="https://www.helloimg.com/image/oGcCSE">
        <img   class="lazyload lazyload-gif"
          src="/images/loading.svg" data-src="https://www.helloimg.com/images/2023/01/12/oGcCSE.png"  alt="Gazebo" border="0" />
      </a></p>
<p>However, it doesn’t do anything, and is missing lots of key information that ROS would need to use this robot. Previously we had been using joint_state_publisher to specify the pose of each joint. However, the robot itself should provide that information in the real world or in gazebo. Yet without specifying that, Gazebo doesn’t know to publish that information.</p>
<p>然而，它什么都不做，并且丢失了ROS使用该机器人所需的许多关键信息。之前我们一直使用joint_state_publisher来指定每个关节的姿势。然而，机器人本身应该在现实世界或瞪眼中提供这些信息。然而，在没有具体说明的情况下，Gazebo不知道要发布这些信息。</p>
<p>To get the robot to be interactive (with you and ROS), we need to specify two things: Plugins and Transmissions.</p>
<p>为了让机器人与你和ROS互动，我们需要指定两件事：插件和传输。</p>

        <h2 id="2-gazebo-plugin"   >
          <a href="#2-gazebo-plugin" class="heading-link"><i class="fas fa-link"></i></a><a class="markdownIt-Anchor" href="#2-gazebo-plugin"></a> 2 Gazebo Plugin</h2>
      
<p>To get ROS to interact with Gazebo, we have to dynamically link to the ROS library that will tell Gazebo what to do. Theoretically, this allows for other Robot Operating Systems to interact with Gazebo in a generic way. In practice, its just ROS.</p>
<p>为了让ROS与Gazebo交互，我们必须动态链接到ROS库，该库将告诉Gazebo该做什么。理论上，这允许其他机器人操作系统以通用方式与Gazebo交互。实际上，这只是ROS。</p>
<p>To link Gazebo and ROS, we specify the plugin in the URDF, right before the closing </robot> tag:</p>
<p>要链接Gazebo和ROS，我们在URDF中指定插件，就在关闭</robot>标签之前：</p>
<figure class="highlight xml"><div class="table-container"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">gazebo</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">plugin</span> <span class="attr">name</span>=<span class="string">&quot;gazebo_ros_control&quot;</span> <span class="attr">filename</span>=<span class="string">&quot;libgazebo_ros_control.so&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">robotNamespace</span>&gt;</span>/<span class="tag">&lt;/<span class="name">robotNamespace</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">plugin</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">gazebo</span>&gt;</span></span><br></pre></td></tr></table></div></figure>
<p>You can see this in <span class="exturl"><a class="exturl__link"   target="_blank" rel="noopener" href="https://github.com/ros/urdf_sim_tutorial/blob/master/urdf/09-publishjoints.urdf.xacro" >https://github.com/ros/urdf_sim_tutorial/blob/master/urdf/09-publishjoints.urdf.xacro</a><span class="exturl__icon"><i class="fas fa-external-link-alt"></i></span></span> and by running <code>roslaunch urdf_sim_tutorial gazebo.launch model:=urdf/09-publishjoints.urdf.xacro</code></p>
<p>你可以在<span class="exturl"><a class="exturl__link"   target="_blank" rel="noopener" href="https://github.com/ros/urdf_sim_tutorial/blob/master/urdf/09-publishjoints.urdf.xacro%E5%B9%B6%E9%80%9A%E8%BF%87%E8%BF%90%E8%A1%8C%60roslaunch" >https://github.com/ros/urdf_sim_tutorial/blob/master/urdf/09-publishjoints.urdf.xacro并通过运行`roslaunch</a><span class="exturl__icon"><i class="fas fa-external-link-alt"></i></span></span> urdf_sim_tutorial gazebo.launch model:=urdf/09-publishjoints.urdf.xacro`</p>
<p>However, this won’t do anything new yet. For that we need to specify more information outside the URDF.</p>
<p>然而，这还没有什么新的作用。为此，我们需要在URDF之外指定更多信息。</p>

        <h2 id="3-spawning-controllers"   >
          <a href="#3-spawning-controllers" class="heading-link"><i class="fas fa-link"></i></a><a class="markdownIt-Anchor" href="#3-spawning-controllers"></a> 3 Spawning Controllers</h2>
      
<p>Now that we’ve linked ROS and Gazebo, we need to specify some bits of ROS code that we want to run within Gazebo, which we generically call controllers. These are initially loaded into the ROS parameter space. We have a yaml file joints.yaml that specifies our first controller.</p>
<p>现在我们已经链接了ROS和Gazebo，我们需要指定一些要在Gazebo中运行的ROS代码，我们通常称之为控制器。这些初始加载到ROS参数空间。我们有一个指定第一个控制器的yaml文件joints.yaml。</p>
<figure class="highlight plaintext"><div class="table-container"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">type: &quot;joint_state_controller/JointStateController&quot;</span><br><span class="line">publish_rate: 50</span><br></pre></td></tr></table></div></figure>
<p>This controller is found in the joint_state_controller package and publishes the state of the robot’s joints into ROS directly from Gazebo.</p>
<p>该控制器位于joint_state_controller包中，并将机器人关节的状态直接从Gazebo发布到ROS中。</p>
<p>In 09-joints.launch you can see how we should load this yaml file into the r2d2_joint_state_controller namespace. Then we call the [[controller_manager]]/spawner script with that namespace which loads it into Gazebo.</p>
<p>在09-joints.launch中，您可以看到如何将这个yaml文件加载到r2d2_joint_state_controller命名空间中。然后，我们使用该名称空间调用[[controller_manager]]/spowner脚本，将其加载到Gazebo中。</p>
<p>You can launch this, but its still not quite there.  roslaunch urdf_sim_tutorial 09-joints.launch</p>
<p>你可以启动这个，但它仍然不太到位。roslaunch urdf_sim_tutorial 09-joints.launch</p>
<p>This will run the controller and in fact publish on the /joint_states topic…but with nothing in them.</p>
<p>这将运行控制器，并实际上在/joint_states主题上发布。。。。但里面什么都没有。</p>
<figure class="highlight plaintext"><div class="table-container"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">header:</span><br><span class="line">  seq: 652</span><br><span class="line">  stamp:</span><br><span class="line">    secs: 13</span><br><span class="line">    nsecs: 331000000</span><br><span class="line">  frame_id: &#x27;&#x27;</span><br><span class="line">name: []</span><br><span class="line">position: []</span><br><span class="line">velocity: []</span><br><span class="line">effort: []</span><br></pre></td></tr></table></div></figure>
<p>What else do you want Gazebo!? Well, it wants to know what joints to publish information about.</p>
<p>你还想要什么Gazebo！？嗯，它想知道要发布关于哪些关节的信息。</p>

        <h2 id="4-transmissions"   >
          <a href="#4-transmissions" class="heading-link"><i class="fas fa-link"></i></a><a class="markdownIt-Anchor" href="#4-transmissions"></a> 4 Transmissions</h2>
      
<p>For every non-fixed joint, we need to specify a transmission, which tells Gazebo what to do with the joint. Let’s start with the head joint. Add the following to your URDF:</p>
<p>对于每个非固定接头，我们需要指定一个变速器，它告诉Gazebo如何处理接头。让我们从头部关节开始。将以下内容添加到URDF中：</p>
<figure class="highlight xml"><div class="table-container"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">transmission</span> <span class="attr">name</span>=<span class="string">&quot;head_swivel_trans&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">type</span>&gt;</span>transmission_interface/SimpleTransmission<span class="tag">&lt;/<span class="name">type</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">actuator</span> <span class="attr">name</span>=<span class="string">&quot;$head_swivel_motor&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">mechanicalReduction</span>&gt;</span>1<span class="tag">&lt;/<span class="name">mechanicalReduction</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">actuator</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">joint</span> <span class="attr">name</span>=<span class="string">&quot;head_swivel&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">hardwareInterface</span>&gt;</span>hardware_interface/PositionJointInterface<span class="tag">&lt;/<span class="name">hardwareInterface</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">joint</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">transmission</span>&gt;</span></span><br></pre></td></tr></table></div></figure>
<ul>
<li>
<p>For introductory purposes, just treat most of this chunk of code as boilerplate.</p>
</li>
<li>
<p>The first thing to note is the joint element. The name should match the joint declared earlier.</p>
</li>
<li>
<p>The hardwareInterface will be important as we explore the plugins.</p>
</li>
<li>
<p>出于介绍目的，只需将这段代码的大部分作为样板。</p>
</li>
<li>
<p>首先要注意的是关节元素。名称应与前面声明的关节匹配。</p>
</li>
<li>
<p>在我们探索插件时，hardwareInterface将非常重要。</p>
</li>
</ul>
<p>You can run this URDF with our previous launch configuration. <code>roslaunch urdf_sim_tutorial 09-joints.launch model:=urdf/10-firsttransmission.urdf.xacro</code></p>
<p>Now, the head is displayed properly in RViz because the head joint is listed in the joint_states messages.</p>
<p>您可以使用我们以前的启动配置运行此URDF。<code>roslaunch urdf_sim_tutorial 09-joints.launch model:=urdf/10-firsttransmission.urdf.xacro</code></p>
<p>现在，头部在RViz中正确显示，因为头部关节列在joint_states消息中。</p>

        <h2 id="5-joint-control"   >
          <a href="#5-joint-control" class="heading-link"><i class="fas fa-link"></i></a><a class="markdownIt-Anchor" href="#5-joint-control"></a> 5 Joint Control</h2>
      
<p>Here’s the next controller config we’re adding.</p>
<p>这是我们要添加的下一个控制器配置。</p>
<figure class="highlight plaintext"><div class="table-container"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">type: &quot;position_controllers/JointPositionController&quot;</span><br><span class="line">joint: head_swivel</span><br></pre></td></tr></table></div></figure>
<p>This specifies to use the a JointPositionController from the position_controllers package to control the head_swivel transmission. Note that hardware interface in the URDF for this joint matches the controller type.</p>
<p>这指定使用position_controllers包中的JointPositionController来控制head_swivel传输。注意，此接头的URDF中的硬件接口与控制器类型匹配。</p>
<p>Now we can launch this with the added config as before  roslaunch urdf_sim_tutorial 10-head.launch</p>
<p>现在，我们可以像之前一样使用添加的配置来启动它，如roslaunch urdf_sim_tutorial 10-head.launch</p>
<p>Now Gazebo is subscribed to a new topic, and you can then control the position of the head by publishing a value in ROS. <code>rostopic pub /r2d2_head_controller/command std_msgs/Float64 &quot;data: -0.707&quot;</code></p>
<p>现在Gazebo订阅了一个新主题，然后您可以通过在ROS中发布值来控制负责人的位置。<code>rostopic pub /r2d2_head_controller/command std_msgs/Float64 &quot;data: -0.707&quot;</code></p>
<p>When this command is published, the position will immediately change to the specified value. This is because we did not specify any limits for the joint in our urdf. However, if we change the joint, it will move gradually.</p>
<p>发布此命令后，位置将立即更改为指定值。这是因为我们在urdf中没有为关节指定任何限制。然而，如果我们改变关节，它会逐渐移动。</p>
<figure class="highlight xml"><div class="table-container"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">joint</span> <span class="attr">name</span>=<span class="string">&quot;head_swivel&quot;</span> <span class="attr">type</span>=<span class="string">&quot;continuous&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">parent</span> <span class="attr">link</span>=<span class="string">&quot;base_link&quot;</span>/&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">child</span> <span class="attr">link</span>=<span class="string">&quot;head&quot;</span>/&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">axis</span> <span class="attr">xyz</span>=<span class="string">&quot;0 0 1&quot;</span>/&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">origin</span> <span class="attr">xyz</span>=<span class="string">&quot;0 0 $&#123;bodylen/2&#125;&quot;</span>/&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">limit</span> <span class="attr">effort</span>=<span class="string">&quot;30&quot;</span> <span class="attr">velocity</span>=<span class="string">&quot;1.0&quot;</span>/&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">joint</span>&gt;</span></span><br></pre></td></tr></table></div></figure>
<figure class="highlight sh"><div class="table-container"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">roslaunch urdf_sim_tutorial 10-head.launch model:=urdf/11-limittransmission.urdf.xacro</span><br></pre></td></tr></table></div></figure>

        <h2 id="6-another-controller"   >
          <a href="#6-another-controller" class="heading-link"><i class="fas fa-link"></i></a><a class="markdownIt-Anchor" href="#6-another-controller"></a> 6 Another Controller</h2>
      
<p>We can change the URDF for the Gripper joints in a similar way. However, instead of individually controlling each joint of the gripper with its own ROS topic, we might want to group them together. For this, we just need to specify a different controller in the ROS parameters.</p>
<p>我们可以以类似的方式更改夹持器关节的URDF。然而，我们可能希望将它们分组在一起，而不是用自己的ROS主题单独控制夹持器的每个关节。为此，我们只需要在ROS参数中指定一个不同的控制器。</p>
<figure class="highlight plaintext"><div class="table-container"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">type: &quot;position_controllers/JointGroupPositionController&quot;</span><br><span class="line">joints:</span><br><span class="line">  - gripper_extension</span><br><span class="line">  - left_gripper_joint</span><br><span class="line">  - right_gripper_joint</span><br></pre></td></tr></table></div></figure>
<p>To launch this, <code>roslaunch urdf_sim_tutorial 12-gripper.launch </code></p>
<p>要启动此功能，请执行<code>roslaunch urdf_sim_tutorial 12-gripper.launch</code></p>
<p>With this, we can instead specify the position with an array of floats. Open and out:</p>
<p>使用此选项，我们可以使用浮点数组指定位置。打开和输出：</p>
<figure class="highlight plaintext"><div class="table-container"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">rostopic pub  /r2d2_gripper_controller/command std_msgs/Float64MultiArray &quot;layout:</span><br><span class="line">  dim:</span><br><span class="line">  - label: &#x27;&#x27;</span><br><span class="line">    size: 3</span><br><span class="line">    stride: 1</span><br><span class="line">  data_offset: 0</span><br><span class="line">data: [0, 0.5, 0.5]&quot;</span><br></pre></td></tr></table></div></figure>
<p>Closed and retracted:</p>
<p>关闭和缩回：</p>
<figure class="highlight plaintext"><div class="table-container"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">rostopic pub  /r2d2_gripper_controller/command std_msgs/Float64MultiArray &quot;layout:</span><br><span class="line">  dim:</span><br><span class="line">  - label: &#x27;&#x27;</span><br><span class="line">    size: 3</span><br><span class="line">    stride: 1</span><br><span class="line">  data_offset: 0</span><br><span class="line">data: [-0.4, 0, 0]&quot;</span><br></pre></td></tr></table></div></figure>

        <h2 id="7-the-wheels-on-the-droid-go-round-and-round"   >
          <a href="#7-the-wheels-on-the-droid-go-round-and-round" class="heading-link"><i class="fas fa-link"></i></a><a class="markdownIt-Anchor" href="#7-the-wheels-on-the-droid-go-round-and-round"></a> 7 The Wheels on the Droid Go Round and Round</h2>
      
<p>To drive the robot around, we specify yet another transmission for each of the wheels from within the wheel macro.</p>
<p>为了驱动机器人，我们在轮子宏中为每个轮子指定了另一个传动装置。</p>
<figure class="highlight xml"><div class="table-container"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">transmission</span> <span class="attr">name</span>=<span class="string">&quot;$&#123;prefix&#125;_$&#123;suffix&#125;_wheel_trans&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">type</span>&gt;</span>transmission_interface/SimpleTransmission<span class="tag">&lt;/<span class="name">type</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">actuator</span> <span class="attr">name</span>=<span class="string">&quot;$&#123;prefix&#125;_$&#123;suffix&#125;_wheel_motor&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">mechanicalReduction</span>&gt;</span>1<span class="tag">&lt;/<span class="name">mechanicalReduction</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">actuator</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">joint</span> <span class="attr">name</span>=<span class="string">&quot;$&#123;prefix&#125;_$&#123;suffix&#125;_wheel_joint&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">hardwareInterface</span>&gt;</span>hardware_interface/VelocityJointInterface<span class="tag">&lt;/<span class="name">hardwareInterface</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">joint</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">transmission</span>&gt;</span></span><br></pre></td></tr></table></div></figure>
<p>This is just like the other transmissions, except</p>
<ul>
<li>It uses macro parameters to specify names</li>
<li>It uses a VelocityJointInterface.</li>
</ul>
<p>这和其他变速器一样，除了</p>
<ul>
<li>它使用宏参数指定名称</li>
<li>它使用VelocityJointInterface。</li>
</ul>
<p>Since the wheels are actually going to touch the ground and thus interact with it physically, we also specify some additional information about the material of the wheels.</p>
<p>由于车轮实际上会接触地面，从而与地面物理交互，因此我们还指定了有关车轮材料的一些附加信息。</p>
<figure class="highlight xml"><div class="table-container"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">gazebo</span> <span class="attr">reference</span>=<span class="string">&quot;$&#123;prefix&#125;_$&#123;suffix&#125;_wheel&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">mu1</span> <span class="attr">value</span>=<span class="string">&quot;200.0&quot;</span>/&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">mu2</span> <span class="attr">value</span>=<span class="string">&quot;100.0&quot;</span>/&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">kp</span> <span class="attr">value</span>=<span class="string">&quot;10000000.0&quot;</span> /&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">kd</span> <span class="attr">value</span>=<span class="string">&quot;1.0&quot;</span> /&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">material</span>&gt;</span>Gazebo/Grey<span class="tag">&lt;/<span class="name">material</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">gazebo</span>&gt;</span></span><br></pre></td></tr></table></div></figure>
<p>See <span class="exturl"><a class="exturl__link"   target="_blank" rel="noopener" href="http://gazebosim.org/tutorials/?tut=ros_urdf" >http://gazebosim.org/tutorials/?tut=ros_urdf</a><span class="exturl__icon"><i class="fas fa-external-link-alt"></i></span></span> for more details.</p>
<p><span class="exturl"><a class="exturl__link"   target="_blank" rel="noopener" href="http://gazebosim.org/tutorials/?tut=ros_urdf" >http://gazebosim.org/tutorials/?tut=ros_urdf</a><span class="exturl__icon"><i class="fas fa-external-link-alt"></i></span></span> 了解更多详情。</p>
<p>We could specify controllers for each of the individual wheels, but where’s the fun in that? Instead we want to control all the wheels together. For that, we’re going to need a lot more ROS parameters.</p>
<p>我们可以为每个单独的轮子指定控制器，但这其中的乐趣何在？相反，我们希望一起控制所有车轮。为此，我们需要更多的ROS参数。</p>
<figure class="highlight plaintext"><div class="table-container"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line">type: &quot;diff_drive_controller/DiffDriveController&quot;</span><br><span class="line">publish_rate: 50</span><br><span class="line"></span><br><span class="line">left_wheel: [&#x27;left_front_wheel_joint&#x27;, &#x27;left_back_wheel_joint&#x27;]</span><br><span class="line">right_wheel: [&#x27;right_front_wheel_joint&#x27;, &#x27;right_back_wheel_joint&#x27;]</span><br><span class="line"></span><br><span class="line">wheel_separation: 0.44</span><br><span class="line"></span><br><span class="line"># Odometry covariances for the encoder output of the robot. These values should</span><br><span class="line"># be tuned to your robot&#x27;s sample odometry data, but these values are a good place</span><br><span class="line"># to start</span><br><span class="line">pose_covariance_diagonal: [0.001, 0.001, 0.001, 0.001, 0.001, 0.03]</span><br><span class="line">twist_covariance_diagonal: [0.001, 0.001, 0.001, 0.001, 0.001, 0.03]</span><br><span class="line"></span><br><span class="line"># Top level frame (link) of the robot description</span><br><span class="line">base_frame_id: base_link</span><br><span class="line"></span><br><span class="line"># Velocity and acceleration limits for the robot</span><br><span class="line">linear:</span><br><span class="line">  x:</span><br><span class="line">    has_velocity_limits    : true</span><br><span class="line">    max_velocity           : 0.2   # m/s</span><br><span class="line">    has_acceleration_limits: true</span><br><span class="line">    max_acceleration       : 0.6   # m/s^2</span><br><span class="line">angular:</span><br><span class="line">  z:</span><br><span class="line">    has_velocity_limits    : true</span><br><span class="line">    max_velocity           : 2.0   # rad/s</span><br><span class="line">    has_acceleration_limits: true</span><br><span class="line">    max_acceleration       : 6.0   # rad/s^2</span><br></pre></td></tr></table></div></figure>
<p>The DiffDriveController subscribes to a standard Twist cmd_vel message and moves the robot accordingly.</p>
<p>DiffDriveController订阅标准Twist cmd_vel消息，并相应地移动机器人。</p>
<figure class="highlight sh"><div class="table-container"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">roslaunch urdf_sim_tutorial 13-diffdrive.launch</span><br></pre></td></tr></table></div></figure>
<p>In addition to loading the above configuration, this also opens the RobotSteering panel, allowing you to drive the R2D2 robot around, while also observing its actual behavior (in Gazebo) and it’s visualized behavior (in RViz):</p>
<p>除了加载上述配置，这还将打开RobotSteering面板，允许您驾驶R2D2机器人四处走动，同时观察其实际行为（在Gazebo中）和可视化行为（在RViz中）：</p>
<p><a target="_blank" rel="noopener" href="https://www.helloimg.com/image/oGcRy9">
        <img   class="lazyload lazyload-gif"
          src="/images/loading.svg" data-src="https://www.helloimg.com/images/2023/01/12/oGcRy9.png"  alt="DrivingInterface" border="0" />
      </a></p>
<p>Congrats! Now you’re simulating robots with URDF.</p>
<p>恭喜！现在您正在使用URDF模拟机器人。</p>
</div><footer class="post-footer"><div class="post-ending ending"><div class="ending__text">------ 本文结束，感谢您的阅读 ------</div></div><div class="post-copyright copyright"><div class="copyright-author"><span class="copyright-author__name">本文作者: </span><span class="copyright-author__value"><a href="http://hipposox.github.io">HippoSoX</a></span></div><div class="copyright-link"><span class="copyright-link__name">本文链接: </span><span class="copyright-link__value"><a href="http://hipposox.github.io/2023/01/10/urdf-tutorials-04/">http://hipposox.github.io/2023/01/10/urdf-tutorials-04/</a></span></div><div class="copyright-notice"><span class="copyright-notice__name">版权声明: </span><span class="copyright-notice__value">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.en" rel="external nofollow" target="_blank">BY-NC-SA</a> 许可协议。转载请注明出处！</span></div></div><div class="post-tags"><span class="post-tags-item"><span class="post-tags-item__icon"><i class="fas fa-tag"></i></span><a class="post-tags-item__link" href="http://hipposox.github.io/tags/ros/">ros</a></span><span class="post-tags-item"><span class="post-tags-item__icon"><i class="fas fa-tag"></i></span><a class="post-tags-item__link" href="http://hipposox.github.io/tags/URDF/">URDF</a></span><span class="post-tags-item"><span class="post-tags-item__icon"><i class="fas fa-tag"></i></span><a class="post-tags-item__link" href="http://hipposox.github.io/tags/Gazebo/">Gazebo</a></span></div><nav class="post-paginator paginator"><div class="paginator-prev"><a class="paginator-prev__link" href="/2023/01/11/OCCT-Introduction/"><span class="paginator-prev__icon"><i class="fas fa-angle-left"></i></span><span class="paginator-prev__text">OCCT_Introduction</span></a></div><div class="paginator-next"><a class="paginator-next__link" href="/2023/01/10/urdf-tutorials-03/"><span class="paginator-prev__text">【urdf_tutorials】Using Xacro to Clean Up a URDF File 使用Xacro清理URDF文件</span><span class="paginator-next__icon"><i class="fas fa-angle-right"></i></span></a></div></nav></footer></div></div></div><div class="sidebar-wrap" id="sidebar-wrap"><aside class="sidebar" id="sidebar"><div class="sidebar-nav"><span class="sidebar-nav-toc current">文章目录</span><span class="sidebar-nav-ov">站点概览</span></div><section class="sidebar-toc"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#using-a-urdf-in-gazebo-%E5%9C%A8gazebo%E4%B8%AD%E4%BD%BF%E7%94%A8urdf"><span class="toc-number">1.</span> <span class="toc-text">
           Using a URDF in Gazebo 在Gazebo中使用URDF</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-nonfunctional-gazebo-interface"><span class="toc-number">1.1.</span> <span class="toc-text">
           1 Nonfunctional Gazebo Interface</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-gazebo-plugin"><span class="toc-number">1.2.</span> <span class="toc-text">
           2 Gazebo Plugin</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-spawning-controllers"><span class="toc-number">1.3.</span> <span class="toc-text">
           3 Spawning Controllers</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4-transmissions"><span class="toc-number">1.4.</span> <span class="toc-text">
           4 Transmissions</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#5-joint-control"><span class="toc-number">1.5.</span> <span class="toc-text">
           5 Joint Control</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#6-another-controller"><span class="toc-number">1.6.</span> <span class="toc-text">
           6 Another Controller</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#7-the-wheels-on-the-droid-go-round-and-round"><span class="toc-number">1.7.</span> <span class="toc-text">
           7 The Wheels on the Droid Go Round and Round</span></a></li></ol></li></ol></section><!-- ov = overview--><section class="sidebar-ov hide"><div class="sidebar-ov-author"><div class="sidebar-ov-author__avatar"><img class="sidebar-ov-author__avatar_img" src="/images/icons/stun-logo.svg" alt="avatar"></div><p class="sidebar-ov-author__text">motto</p></div><div class="sidebar-ov-state"><a class="sidebar-ov-state-item sidebar-ov-state-item--posts" href="/archives/"><div class="sidebar-ov-state-item__count">19</div><div class="sidebar-ov-state-item__name">归档</div></a><a class="sidebar-ov-state-item sidebar-ov-state-item--categories" href="/categories/"><div class="sidebar-ov-state-item__count">6</div><div class="sidebar-ov-state-item__name">分类</div></a><a class="sidebar-ov-state-item sidebar-ov-state-item--tags" href="/tags/"><div class="sidebar-ov-state-item__count">14</div><div class="sidebar-ov-state-item__name">标签</div></a></div><div class="sidebar-ov-cc"><a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.en" target="_blank" rel="noopener" data-popover="知识共享许可协议" data-popover-pos="up"><img src="/images/cc-by-nc-sa.svg"></a></div></section><div class="sidebar-reading"><div class="sidebar-reading-info"><span class="sidebar-reading-info__text">你已阅读了 </span><span class="sidebar-reading-info__num">0</span><span class="sidebar-reading-info__perc">%</span></div><div class="sidebar-reading-line"></div></div><iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=330 height=86 src="//music.163.com/outchain/player?type=2&id=1449790718&auto=1&height=66"></iframe></aside></div><div class="clearfix"></div></div></main><footer class="footer" id="footer"><div class="footer-inner"><div><span>Copyright © 2023</span><span class="footer__icon"><i class="fas fa-heart"></i></span><span>HippoSoX</span></div><div><span>由 <a href="http://hexo.io/" title="Hexo" target="_blank" rel="noopener">Hexo</a> 强力驱动</span><span> v5.4.2</span><span class="footer__devider">|</span><span>主题 - <a href="https://github.com/liuyib/hexo-theme-stun/" title="Stun" target="_blank" rel="noopener">Stun</a></span><span> v2.8.0</span></div></div></footer><div class="loading-bar" id="loading-bar"><div class="loading-bar__progress"></div></div><div class="back2top" id="back2top"><span class="back2top__icon"><i class="fas fa-rocket"></i></span></div></div><script src="https://cdn.jsdelivr.net/npm/jquery@v3.4.1/dist/jquery.min.js"></script><script src="https://cdn.jsdelivr.net/npm/velocity-animate@1.5.2/velocity.min.js"></script><script src="https://cdn.jsdelivr.net/npm/velocity-animate@1.5.2/velocity.ui.min.js"></script><script src="https://cdn.jsdelivr.net/npm/lazyload@2.0.0-rc.2/lazyload.min.js"></script><script src="/js/utils.js?v=2.8.0"></script><script src="/js/stun-boot.js?v=2.8.0"></script><script src="/js/scroll.js?v=2.8.0"></script><script src="/js/header.js?v=2.8.0"></script><script src="/js/sidebar.js?v=2.8.0"></script></body></html>